package com.kawaiior.asoulworld.items.weapon;

import com.kawaiior.asoulworld.items.AsWeaponBase;
import com.kawaiior.asoulworld.potion.ModPotions;
import com.kawaiior.asoulworld.util.EntityUtil;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.EnumAction;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ActionResult;
import net.minecraft.util.EnumHand;
import net.minecraft.world.World;

import javax.annotation.Nonnull;

public class ItemCarolFansSword extends AsWeaponBase {
    public ItemCarolFansSword(String name) {
        super(name);
        this.attack_damage = 7f;
        this.max_damage = 1024;
    }

    @Override
    public int getMaxItemUseDuration(ItemStack stack)
    {
        return 72000;
    }

    @Override
    public EnumAction getItemUseAction(ItemStack stack)
    {
        return EnumAction.BOW;
    }

    @Nonnull
    @Override
    public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, @Nonnull EnumHand hand) {
        if (!world.isRemote && !player.isPotionActive(ModPotions.COUNTER_ATTACK))
        {
            player.setActiveHand(hand);
            EntityUtil.ApplyBuff(player, ModPotions.COUNTER_ATTACK,0,2f);
        }
        return super.onItemRightClick(world,player,hand);
    }

    @Override
    public void onPlayerStoppedUsing(ItemStack stack, World worldIn, EntityLivingBase entityLiving, int timeLeft)
    {
        if (entityLiving instanceof EntityPlayer)
        {
            EntityPlayer player = (EntityPlayer)entityLiving;
            player.getCooldownTracker().setCooldown(this, 160);
            player.removePotionEffect(ModPotions.COUNTER_ATTACK);
            stack.damageItem(8, player);
        }
    }

}
